package org.wmq.taskschedule.algorithm;

import org.opencv.core.Mat;
import org.opencv.core.Size;
import org.opencv.imgproc.Imgproc;

/**
 * 高斯模糊算法执行器
 * 实现AlgorithmExecutor接口，用于对图像进行高斯模糊处理
 */
public class GaussianBlurExecutor implements AlgorithmExecutor {

    private int kernelWidth; // 核宽度
    private int kernelHeight; // 核高度
    private double sigmaX; // X方向标准差
    private double sigmaY; // Y方向标准差
    private String description; // 算法描述

    /**
     * 默认构造函数，使用默认参数
     */
    public GaussianBlurExecutor() {
        this.kernelWidth = 3;
        this.kernelHeight = 3;
        this.sigmaX = 0;
        this.sigmaY = 0;
        this.description = "高斯模糊算法 - 对图像进行高斯模糊处理，去除噪声";
    }

    /**
     * 构造函数，允许自定义参数
     * 
     * @param kernelWidth 核宽度
     * @param kernelHeight 核高度
     * @param sigmaX X方向标准差
     * @param sigmaY Y方向标准差
     */
    public GaussianBlurExecutor(int kernelWidth, int kernelHeight, double sigmaX, double sigmaY) {
        this.kernelWidth = kernelWidth;
        this.kernelHeight = kernelHeight;
        this.sigmaX = sigmaX;
        this.sigmaY = sigmaY;
        this.description = "高斯模糊算法 - 对图像进行高斯模糊处理，去除噪声";
    }

    /**
     * 构造函数，允许自定义所有参数
     * 
     * @param kernelWidth 核宽度
     * @param kernelHeight 核高度
     * @param sigmaX X方向标准差
     * @param sigmaY Y方向标准差
     * @param description 算法描述
     */
    public GaussianBlurExecutor(int kernelWidth, int kernelHeight, double sigmaX, double sigmaY, String description) {
        this.kernelWidth = kernelWidth;
        this.kernelHeight = kernelHeight;
        this.sigmaX = sigmaX;
        this.sigmaY = sigmaY;
        this.description = description;
    }

    @Override
    public Mat execute(Mat input) {
        if (input == null || input.empty()) {
            throw new IllegalArgumentException("输入图像不能为空");
        }

        // 创建输出图像
        Mat output = new Mat();

        // 应用高斯模糊算法
        Imgproc.GaussianBlur(input, output, new Size(kernelWidth, kernelHeight), sigmaX, sigmaY);

        return output;
    }

    // Getters and setters
    public int getKernelWidth() {
        return kernelWidth;
    }

    public void setKernelWidth(int kernelWidth) {
        this.kernelWidth = kernelWidth;
    }

    public int getKernelHeight() {
        return kernelHeight;
    }

    public void setKernelHeight(int kernelHeight) {
        this.kernelHeight = kernelHeight;
    }

    public double getSigmaX() {
        return sigmaX;
    }

    public void setSigmaX(double sigmaX) {
        this.sigmaX = sigmaX;
    }

    public double getSigmaY() {
        return sigmaY;
    }

    public void setSigmaY(double sigmaY) {
        this.sigmaY = sigmaY;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }
}